package org.fastiot.data.archives

import grails.testing.gorm.DomainUnitTest
import org.fastiot.data.DataSet
import spock.lang.Specification

class LatestSpec extends Specification implements DomainUnitTest<Latest> {

    def setup() {
    }

    def cleanup() {
    }

    void "Test a valid properties"() {
        given:
        def instance = new Latest(
                terminalCode: terminalCode, dateAcquired: dateAcquired,
                dataSet: dataSet, metadata: metadata, contents: contents
        )

        when:
        instance.save(flush: true)

        then:
        !instance.hasErrors()

        where:
        terminalCode << ["LN1234567890123456"]
        dateAcquired << [new GregorianCalendar(2018, 2, 14, 12, 13, 14).time]
        dataSet << [
                new DataSet(code: "ds1", name: "数据集1", scene: DataSet.AggregateScene.RealTime).save(flush: true)
        ]
        metadata << [
                [
                        [code: 'SOC', name: "荷电状态"], [code: 'KPH', name: "时速"], [code: 'LAT', name: "纬度"],
                        [code: 'LON', name: "经度"], [code: 'TEMP', name: "温度"], [code: 'VIB', name: "振动"],
                        [code: 'WARN', name: "报警", enumRange: [0: "正常", 1: "故障"]]
                ]
        ]
        contents << [
                [80, 37.5, 39.5427, 116.2317, 80.3, 10.5, 0]
        ]
    }
}
